package com.ht.medicaltreatment.viewmodel

import com.hjq.http.EasyHttp
import com.hjq.http.listener.OnHttpListener
import com.ht.medicaltreatment.api.ConsumableBindingSampleAPI
import com.ht.medicaltreatment.api.ConsumableSampleAPI
import com.ht.medicaltreatment.bean.ConsumableSampleBean
import com.ht.medicaltreatment.bean.ConsumableSampleData
import com.ht.medicaltreatment.bean.SuccessBean

class ConsumableSampleViewModel:BaseViewModel() {
    fun requestList(id:String,OnSuccess:(MutableList<ConsumableSampleData>)->Unit){
        EasyHttp.post(this)
            .api(ConsumableSampleAPI(id))
            .request(object :OnHttpListener<ConsumableSampleBean>{
                override fun onHttpSuccess(result:ConsumableSampleBean) {
                    if(result.code == 200){
                        OnSuccess(result.data)
                    }else{
                        dismissProgress(result.message)
                    }
                }

                override fun onHttpFail(e: Exception) {
                    dismissProgress(e.message?:"请求错误")
                }
            })
    }

    fun binding(rfidCode:String,batchentryRfidSampId:String,
                OnSuccess:()->Unit,onFail:(String)->Unit){
        EasyHttp.post(this)
            .api(ConsumableBindingSampleAPI(batchentryRfidSampId,rfidCode))
            .request(object :OnHttpListener<SuccessBean>{
                override fun onHttpSuccess(result:SuccessBean) {
                    if(result.code == 200){
                        OnSuccess()
                    }else{
                        dismissProgress(result.message)
                    }
                }

                override fun onHttpFail(e: Exception) {
                    onFail(e.message?:"请求错误")
                }
            })
    }
}